package com.lgqz.himalayafm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lgqz.himalayafm.R;
import com.lgqz.himalayafm.bean.RadioHomeStationEntity;

import java.util.List;

/**
 * Created by Administrator on 2016/12/8/008.
 */
public class RadioStationAdapter extends BaseAdapter {
    private Context context;
    private List<RadioHomeStationEntity.HomeStationEntityData> homeStationData;

    public RadioStationAdapter(Context context, List<RadioHomeStationEntity.HomeStationEntityData> homeStationData) {
        this.context = context;
        this.homeStationData = homeStationData;
    }

    @Override
    public int getCount() {
        return homeStationData.size();
    }

    @Override
    public Object getItem(int position) {
        return homeStationData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RadioStationAdapter.ViewHodler hodler=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.fragment_radios_listview_item, parent, false);
            hodler =  new RadioStationAdapter.ViewHodler(convertView);
            convertView.setTag(hodler);
        }else {
            hodler= (RadioStationAdapter.ViewHodler) convertView.getTag();
        }
        hodler.fristStationname.setText(homeStationData.get(position).getRname());
       // hodler.fristPeoplenum.setText((Integer.parseInt(homeStationData.get(position).getRadioPlayCount())/10000)+"万");
        hodler.fristPeoplenum.setText(homeStationData.get(position).getRadioPlayCount());
        hodler.fristnowStation.setText("正在直播："+homeStationData.get(position).getProgramName());
        hodler.fristlistImage.setImageURI(homeStationData.get(position).getRadioCoverSmall());
        return convertView;
    }
    public static class ViewHodler {

        private final SimpleDraweeView fristlistImage;
        private final TextView fristStationname;
        private final TextView fristnowStation;
        private final TextView fristPeoplenum;
        private final ImageView fristlistplay;

        public ViewHodler(View view) {
            fristlistImage = (SimpleDraweeView) view.findViewById(R.id.radio_listimage_id);
            fristStationname = (TextView) view.findViewById(R.id.radio_liststation_name_id);
            fristnowStation = (TextView) view.findViewById(R.id.radio_fristlist_user);
            fristPeoplenum = (TextView) view.findViewById(R.id.radio_list_people_num);
            fristlistplay = (ImageView) view.findViewById(R.id.radio_frist_play);
        }
    }
}